﻿namespace TestLock
{
    class Program
    {
        static ZhengJian zj = new ZhengJian("张三");
        static Suo suo = new Suo();
        static void Main(string[] args)
        {
            Thread thread = new Thread(Lockzj);
            thread.Start();

            Thread thread2 = new Thread(unLock);
            thread2.Start();
        }

        private static void Lockzj()
        {
            lock (zj)
            {
                Console.WriteLine("证件被锁！");
                Thread.Sleep(1000);
                lock (suo)
                {
                    Console.WriteLine($"我要开锁取证件");
                }
            }
        }
        private static void unLock()
        {
            lock (suo)
            {
                Console.WriteLine("锁匠准备开锁，请出示证件");
                Thread.Sleep(1000);
                lock (zj)
                {
                    Console.WriteLine($"看到 {zj.name} 证件，同意开锁");
                }
            }
        }
        // 证件
        class ZhengJian
        {
            public string name;
            public ZhengJian(string name) => this.name = name;
        }
        class Suo
        {
        }
    }
}